home *** CD-ROM | disk | FTP | other *** search
/ Best of www.BestZips.com (Collector's Edition) / Best of WWW.BESTZIPS.COM Collector's Edition (JCSM Shareware) (JCS Marketing).ISO / tutorial / adatu311.zip / PRINT.ME < prev    next >
Text File  |  1996-01-10  |  88KB  |  2,167 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.  
  8.  
  9.  
  10.  
  11.  
  12.  
  13.  
  14.  
  15.  
  16.  
  17.  
  18.  
  19.                               Welcome  to
  20.                             A D A - T U T R
  21.                        The Interactive Ada Tutor
  22.                         by John J. Herro, Ph.D.
  23.                     Software Innovations Technology
  24.  
  25.                   These are the printed course notes.
  26.  
  27.                         Ver. 3.11, 10 Jan. 1996
  28.  
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.                    Copyright 1988-1996 John J. Herro
  38.  
  39.                     SOFTWARE INNOVATIONS TECHNOLOGY
  40.                           1083 MANDARIN DR NE
  41.                         PALM BAY FL 32905-4706
  42.                              (407)951-0233
  43.  
  44.                    http://members.aol.com/AdaTutor
  45.                     ftp://members.aol.com/AdaTutor
  46.  
  47.                            johnherro@aol.com
  48.                 or: john.herro%374-38-2@satlink.oau.org
  49.  
  50.                   You may make copies of these notes,
  51.                   in printed or machine-readable form.
  52.  
  53.                 You may also copy the computer program.
  54.                      Please see page 1 for details.
  55.  
  56.  
  57.                                                                Page  i
  58.  
  59.                           TABLE OF CONTENTS
  60.  
  61.  
  62. Contents . . . . . . . . . . . . . . . . . . . . . . . . . . . . .   i
  63. Acknowledgments  . . . . . . . . . . . . . . . . . . . . . . . . .  ii
  64. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . .   1
  65. Registration and Licenses - What is Shareware? . . . . . . . . . .   2
  66. Special Offer to Companies, Schools, Etc.  . . . . . . . . . . . .   3
  67. Note to Compiler Companies . . . . . . . . . . . . . . . . . . . .   5
  68. Does Your Screen Show Strange Characters Like Arrows and Brackets?   6
  69. The Ada Reserved Words . . . . . . . . . . . . . . . . . . . . . .   7
  70. Steps for Outside Assignment 1, Preparing to Run Ada . . . . . . .   8
  71. Listings of HELLO.ADA and ADD.ADA  . . . . . . . . . . . . . . . .   9
  72. Listing of TRITEST.ADA . . . . . . . . . . . . . . . . . . . . . .  10
  73. Steps for Outside Assignment 2, Exercise in Enumeration Types  . .  12
  74. Listing of NEXTDATE.ADA  . . . . . . . . . . . . . . . . . . . . .  13
  75. Steps for Outside Assignment 3, Exercise in Records  . . . . . . .  14
  76. Listing of FIBTEST.ADA . . . . . . . . . . . . . . . . . . . . . .  15
  77. Steps for Outside Assignment 4, Exercise in Recursion  . . . . . .  16
  78. Simplified Specification for TEXT_IO . . . . . . . . . . . . . . .  17
  79. Listings of Procedure FILECOPY and Function EXISTS . . . . . . . .  19
  80. Requirements for the Program LEDIT . . . . . . . . . . . . . . . .  20
  81. Steps for Outside Assignment 5, Writing a Simple Line Editor . . .  25
  82. How to Test LEDIT  . . . . . . . . . . . . . . . . . . . . . . . .  26
  83. Listing of LEDIT.ANS . . . . . . . . . . . . . . . . . . . . . . .  29
  84. Listing of TASKING.DUM . . . . . . . . . . . . . . . . . . . . . .  33
  85. Steps for Outside Assignment 6, Exercise in Tasking  . . . . . . .  34
  86. Output from TASKING.EXE After Modification of TASKING.ADA  . . . .  35
  87. Listing of TASKING.ANS . . . . . . . . . . . . . . . . . . . . . .  36
  88.  
  89. Appendix A:  Would You Like a Textbook to Use Along with ADA-TUTR?  37
  90. Appendix B:  Running BOOK to Print All the Screens . . . . . . . .  38
  91. Appendix C:  Some Ada Compilers Available for the PC . . . . . . .  39
  92. Appendix D:  Sample Multi-User Software License  . . . . . . . . .  41
  93. Appendix E:  Installing ADA-TUTR on Other Computers  . . . . . . .  43
  94. Appendix F:  We Listen!  New Features of ADA-TUTR  . . . . . . . .  48
  95. Appendix G:  Disclaimer of Warranty  . . . . . . . . . . . . . . .  50
  96.  
  97.                                                                Page ii
  98.  
  99.                            ACKNOWLEDGMENTS
  100.  
  101. The following trademarks are used in these notes and in the
  102. accompanying files:
  103.  
  104.         ActivAda         Thomson Software Products
  105.         DOS              Microsoft Corp.
  106.         IBM              International Business Machines Corp.
  107.         Janus/Ada        R.R. Software, Inc.
  108.         Open Ada         Meridian Software Systems, Inc.
  109.         UNIX             AT & T
  110.         VAX              Digital Equipment Corporation
  111.         VMS              Digital Equipment Corporation
  112.         Windows          Microsoft Corp.
  113.         Windows 95       Microsoft Corp.
  114.         Windows NT       Microsoft Corp.
  115.  
  116. The file ONECHAR.C was sent to us by Mr. David Hill, 7549 Wynford
  117. Street, Salt Lake City, UT 84121, and the file ALTCHAR.C was sent to
  118. us by Mr. Richard Conn, 22 Hunt Court, Tinton Falls, NJ 07753.  We're
  119. very grateful to Mr. Hill and to Mr. Conn for giving us permission to
  120. include these files in ADA-TUTR.  When used with UNIX.ADA, these files
  121. provide two ways to run the Tutor on UNIX based machines without
  122. having to strike ENTER after each response.  See pages 43-47.
  123.  
  124. The programs in this version of ADA-TUTR were compiled with Janus/Ada
  125. version 2.2.2b, and we're grateful to R.R. Software, Inc. for
  126. permission to distribute the .COM files without restriction.
  127.  
  128.                                                                Page  1
  129.  
  130.                              INTRODUCTION
  131.  
  132.      ADA-TUTR, the Interactive Ada Tutor, will make you an excellent
  133. Ada programmer in minimum time.  You'll learn good Ada program design
  134. techniques, not just Ada syntax.  ADA-TUTR runs on PCs as well as
  135. workstations and mainframes.  On PCs an Ada compiler is helpful, but
  136. not required.  The PC can have any monochrome or color monitor.
  137.      These printed notes aren't meant to be a complete course, or even
  138. a summary, of Ada.  They merely accompany the program ADA-TUTR, which
  139. is a complete course.  You can't "study" these printed notes alone.
  140. For now, just read pages 1, 2, and 6.
  141.      ADA-TUTR lets you learn at your own pace.  So that you don't feel
  142. pressured, ADA-TUTR doesn't keep track of the number of right and
  143. wrong answers.  It simply tells you whether your answers are correct,
  144. and why.  Also, there's no time limit for answering the questions or
  145. completing the Outside Assignments.
  146.      Because I want every programmer to have a chance to learn the
  147. best programming language, I made ADA-TUTR available very economically
  148. as shareware.  Shareware isn't free, but you may TRY this program for
  149. free, and register or buy a license only if you use it.  Please see
  150. pages 2-3 for details.
  151.      Whether or not you use ADA-TUTR and register (or buy a license),
  152. please make unmodified copies of the program and distribute them on
  153. bulletin boards, at clubs, and give them to companies, schools, etc.
  154. You may charge a small fee to copy the program, provided you make it
  155. clear that the fee is only for the copy, and doesn't pay for the
  156. shareware.  (Companies that copy shareware usually charge about $2 to
  157. $10 per diskette.)  Bulletin boards may carry ADA-TUTR even if they
  158. charge for access, and you may include ADA-TUTR on CD-ROMs.  Please
  159. contact us for permission to include ADA-TUTR with other commercial
  160. products, such as Ada compilers (see page 5).  You may add your own
  161. files if you want.  (The files included with ADA-TUTR are briefly
  162. described in FILES.LST.)  If you register, you can earn substantial
  163. money distributing ADA-TUTR; please see page 2 for details.
  164.      Ada will become more and more important, since the Department of
  165. Defense mandated its use in defense software, and is now making it
  166. very hard to obtain waivers.  Although learning Ada takes real effort,
  167. you'll be able to write software that's more reliable and easier to
  168. modify a month or a year later.
  169.      New features of this version of ADA-TUTR are described on pages
  170. 48-49.  Please send me your comments and suggestions.  I wish you
  171. success using ADA-TUTR!
  172.  
  173. John J. Herro, Ph.D.                   SOFTWARE INNOVATIONS TECHNOLOGY
  174.                                        1083 MANDARIN DR NE
  175. johnherro@aol.com                      PALM BAY FL 32905-4706
  176. john.herro%374-38-2@satlink.oau.org    (407) 951-0233
  177.  
  178.                    http://members.aol.com/AdaTutor
  179.                     ftp://members.aol.com/AdaTutor
  180.  
  181.                                                                Page  2
  182.  
  183.             REGISTRATION AND LICENSES - WHAT IS SHAREWARE?
  184.  
  185.      Shareware is a way of marketing a program.  It lets you try the
  186. program before spending money for it.  If you decide to use the
  187. program, you send a small payment to register your copy or buy a
  188. license.  We give you several incentives to do so, explained below.
  189. You're on your honor; you know whether you're "using" ADA-TUTR or
  190. only "trying" it.
  191.      To use ADA-TUTR, individuals register as described below.
  192. Companies, schools, and other organizations can register each
  193. individual who uses the program, or buy a Multi-User License as
  194. described on the next page.
  195.  
  196.                              INDIVIDUALS:
  197.      Register your copy for only $25.  When you register, please give
  198. us the serial number from the ADA-TUTR opening screen.  We'll assign
  199. you a new serial number.  Then run CHANGESN to put your new number
  200. into the program, and give copies to individuals, schools, companies,
  201. clubs, computer bulletin boards, etc.
  202.      We'll send you a commission of $5 for each individual who
  203. registers from one of your copies, and TEN PERCENT for each Multi-User
  204. License sold from one of your copies!  As you can see from the next
  205. page, you can earn up to $240 per license sold!  Commissions are paid
  206. quarterly.  If you like, print the file AD.TXT and use copies as an
  207. advertisement.
  208.      Registration includes the right to use ADA-TUTR as long as you
  209. like, and it includes technical support for one year.  While you have
  210. technical support, we'll inform you of any important updates to
  211. ADA-TUTR, and send you updated copies for only $10 each (free if you
  212. send us a formatted diskette with a stamped diskette mailer).  We're
  213. planning another update of ADA-TUTR some time after Ada 95 compilers
  214. become generally available.  You can renew technical support for only
  215. $10 a year.  Even if you don't renew, you'll continue to receive
  216. commissions.
  217.      When you register, you may order a copy of the current version of
  218. ADA-TUTR, with your serial number.  The price is $10, or free with
  219. your formatted diskette and a stamped diskette mailer.  If you would
  220. like an order form or a price list, please print the file INVOICE.TXT.
  221.      We offer a Customization Kit that lets you edit, add, and delete
  222. ADA-TUTR screens, questions, etc. (even whole topics), producing a new
  223. ADA_TUTR.DAT file.  See the last paragraph on page 4.  Note that the
  224. Customization Kit is not shareware.
  225.      We sell anywhere in the Free World.  We're sorry, but we don't
  226. yet accept credit cards.  Outside the U.S., please remit in U.S. funds
  227. and contact us about extra postal charges on diskettes.
  228.  
  229.              COMPANIES, SCHOOLS, AND OTHER ORGANIZATIONS:
  230.      Please see our special offer for Multi-User Licenses on the next
  231. page.
  232.  
  233.                                                                Page  3
  234.  
  235.                SPECIAL OFFER TO COMPANIES, SCHOOLS, ETC.
  236.  
  237.      ADA-TUTR can be of great benefit to your company, school, or
  238. other organization.  We encourage you to try ADA-TUTR before paying
  239. for it, and you may install ADA-TUTR on your workstations and
  240. mainframes as well as your PCs!  Instructions for installing ADA-TUTR
  241. on other computers are on page 43.
  242.      If you decide to use ADA-TUTR, you could register each individual
  243. user, as described on page 2.  But if you have more than 18 users, you
  244. can save money by buying a Multi-User License, as described here.
  245. You're on your honor; you know whether you're "using" ADA-TUTR or only
  246. "trying" it.  Multi-User Licenses are very reasonably priced, as
  247. follows:
  248.  
  249.  Number of Users:  Price of License:               Note:
  250.  
  251.     Up to  100        only  $450      Send $5 extra for a copy of the
  252.     Up to  500        only  $725      latest version of ADA-TUTR on a
  253.     Up to 2000        only  $950      5.25" diskette, $10 extra for a
  254.     Unlimited         only $2400      copy on a 3.5" diskette.
  255.  
  256.      A license may always be upgraded for only the difference in
  257. price.
  258.      A sample Multi-User license appears on pages 41-42.  A Multi-User
  259. License gives the specified number of people the right to use ADA-TUTR
  260. as long as you like, on all your computers (from small PCs to large
  261. mainframes), at all your locations.  We use the term Multi-User
  262. License rather than Site License because there are no geographic
  263. restrictions.  (Note: If 100 people use ADA-TUTR now and 100 others
  264. use it later, that counts as 200 users, not 100.)  Sales commissions
  265. are NOT paid to Multi-User Licensees.
  266.      A Multi-User License includes one year of technical support,
  267. which can be renewed for only 10% of the price of the license per
  268. year.  While you have technical support, we'll inform you of any
  269. important updates to ADA-TUTR, and send you an updated copy for only
  270. $10.  The update is free if you send a formatted diskette and a
  271. stamped diskette mailer.  We're planning another update of ADA-TUTR
  272. some time after Ada 95 compilers become generally available.
  273.      Even if you don't renew your Technical Support, you'll still have
  274. the right to use ADA-TUTR as long as you like.
  275.      Please print the file INVOICE.TXT, or use your own form.  (When
  276. ordering, please give us the serial number from the opening screen of
  277. your copy of ADA-TUTR, if you have one.)
  278.      We accept Purchase Orders.  Our Federal tax ID number is
  279. 360-40-8382, and we qualify as a Small Business.  We sell anywhere in
  280. the Free World.  We're sorry, but we don't yet accept credit cards.
  281. Outside the U.S., please remit in U.S. funds and contact us about
  282. extra postal charges on diskettes.
  283.  
  284.                                                                Page  4
  285.  
  286.      With shareware, you never have to worry about software piracy,
  287. because your people are ENCOURAGED to copy and distribute the program!
  288. If you prefer, however, a non-shareware version of ADA-TUTR is
  289. available at the same prices.
  290.      If you buy a license, we'll be happy to do minor customization of
  291. ADA-TUTR for you at no charge.  For example, we can add your company
  292. name to the opening screen.  If you'd like major customization,
  293. contact us for terms, or buy our Customization Kit for $195.  Using
  294. any text editor on a PC, workstation, or mainframe, the Customization
  295. Kit lets you edit, add, and delete screens, questions, etc. (even
  296. whole topics), producing a new ADA_TUTR.DAT file.  The Customization
  297. Kit isn't shareware, but you may copy it for use throughout your
  298. organization as required.
  299.  
  300.                                                                Page  5
  301.  
  302.                       NOTE TO COMPILER COMPANIES
  303.  
  304.      A special version of ADA-TUTR is available, without the shareware
  305. notices and without the list of Ada compilers.  It can be customized
  306. for your company, and can run on almost any Ada platform, including
  307. workstations and mainframes, because Ada source code is included.
  308. ADA-TUTR can greatly increase the sales appeal of your compilers and
  309. your Ada tools, whether you sell it separately or include it with your
  310. products.  Please contact us.
  311.      If you're a prospective contractor or subcontractor, the
  312. shareware or special version of ADA-TUTR may be the best and most
  313. economical way for you to supply your customer's Ada educational
  314. needs.  Please contact us before writing your proposal.
  315.  
  316.                                                                Page  6
  317.  
  318.   DOES YOUR SCREEN SHOW STRANGE CHARACTERS LIKE ARROWS AND BRACKETS?
  319.  
  320.      Give the command TYPE READ.ME on your PC.  If one word appears
  321. brighter than the rest, you can skip this page.  However, if your
  322. screen shows strange characters like "[1m" when you TYPE READ.ME or
  323. run ADA_TUTR, you need to read this.
  324.      ADA-TUTR uses ANSI (American National Standards Institute) escape
  325. sequences for highlighting, cursor positioning, reverse video, etc.
  326. Before ADA-TUTR will work correctly on a PC, you must install the
  327. device driver ANSI.SYS, which came with your copy of DOS.  To install
  328. ANSI.SYS, do the following:
  329.  
  330. 1.  If there's a file CONFIG.SYS in the root directory of the disk
  331.     from which you boot, type it and look for a line saying
  332.     "DEVICE=ANSI.SYS" (without the quotes), in either upper or lower
  333.     case.  If that line is not present, add it to CONFIG.SYS anywhere
  334.     in the file, using an ordinary text editor or word processor in
  335.     the non-document mode.  If there's no CONFIG.SYS file, create one
  336.     containing the single line "DEVICE=ANSI.SYS" (without the quotes).
  337.  
  338. 2.  If there's no file ANSI.SYS in your root directory, copy ANSI.SYS
  339.     from your DOS distribution diskette or DOS subdirectory to the
  340.     root directory of the disk from which you boot.
  341.  
  342. 3.  Reboot the computer.  ADA-TUTR should then work correctly.
  343.  
  344.                                                                Page  7
  345.  
  346.                        THE ADA RESERVED WORDS
  347.  
  348.      The reserved words are listed in the Language Reference Manual in
  349. section 2.9, and are repeated here for convenience.
  350.  
  351.   abort         declare        generic      of             select
  352.   abs           delay          goto         or             separate
  353.   abstract *    delta                       others         subtype
  354.   accept        digits                      out
  355.   access        do             if
  356.   aliased *                    in                          tagged *
  357.   all                          is           package        task
  358.   and                                       pragma         terminate
  359.   array                                     private        then
  360.   at                                        procedure      type
  361.                 else           limited      protected *
  362.                 elsif          loop
  363.                 end                                        until *
  364.                 entry                                      use
  365.   begin         exception                   raise
  366.   body          exit           mod          range
  367.                                             record         when
  368.                                             rem            while
  369.                                             renames        with
  370.                                new          requeue *
  371.   case          for            not          return
  372.   constant      function       null         reverse        xor
  373.  
  374.  
  375.  
  376.  
  377.  
  378.  
  379. * Ada 95 only.
  380.  
  381.                                                                Page  8
  382.  
  383.          STEPS FOR OUTSIDE ASSIGNMENT 1, PREPARING TO RUN ADA
  384.  
  385.      For the first Outside Assignment, learn enough about your Ada
  386. compiler to compile and run the two simple programs HELLO.ADA and
  387. ADD.ADA.  Obviously, you have to do this before you can do the
  388. remaining Outside Assignments.
  389.  
  390. 1.  Compile HELLO.ADA.  On most systems, after the Ada compiler is
  391. installed and your library is created, this only involves typing
  392. ADA HELLO or ADA HELLO.ADA.  On some systems, the compiler is invoked
  393. from a menu or "APSE" (Ada Programming Support Environment).
  394.  
  395. 2.  Link, giving the name of the main program, HELLO.  This usually
  396. involves typing LINK HELLO or BIND HELLO, perhaps with some options.
  397. On one system, the command is BAMP HELLO, for Build Ada Main Program!
  398.  
  399. 3.  Run the program.  If your Ada compiler produces native code on a
  400. PC, it created a file HELLO.EXE (or HELLO.COM), and this step simply
  401. involves typing HELLO.  On other systems, the command RUN HELLO is
  402. appropriate.  On some systems, you have to invoke an interpreter to
  403. run the program.
  404.  
  405. 4.  Now compile, link, and run ADD.ADA.
  406.  
  407.      If your compiler implements a subset of Ada, you may have to
  408. modify the programs in this and later Outside Assignments to get them
  409. to compile.  Some subset Ada compilers don't allow "separate"
  410. compilation (used in later assignments), and you'll have to include
  411. the "separate" subprograms inside the main program and compile them as
  412. one.  Some subset compilers don't allow generic instantiation, and
  413. have another way of displaying integers.  In that case, you'll have to
  414. modify ADD.ADA.  If you're using a validated compiler, you won't have
  415. to worry about any of this, because all of the Outside Assignments are
  416. written in standard Ada.
  417.  
  418.                                                                Page  9
  419.  
  420. HELLO.ADA
  421. ---------
  422.  
  423. with Text_IO; use Text_IO;
  424. procedure Hello is
  425. begin
  426.    Put_Line("Hello!");
  427. end Hello;
  428.  
  429.  
  430.  
  431. ADD.ADA
  432. -------
  433.  
  434. with Text_IO; use Text_IO;
  435. procedure Add is
  436.    package My_Int_IO is new Integer_IO(Integer); use My_Int_IO;
  437. begin
  438.    Put(2 + 2);
  439.    New_Line;
  440. end Add;
  441.  
  442.                                                                Page 10
  443. TRITEST.ADA
  444. -----------
  445. with Text_IO; use Text_IO;
  446. procedure Tritest is
  447.    Passed : Boolean := True;
  448.    type Triangle is (Equilateral, Isosceles, Scalene, Not_a_Triangle);
  449.    function Tritype(Len1, Len2, Len3 : in Integer) return Triangle
  450.                                                           is separate;
  451.    procedure Compare(A, B, C: in Integer; Right_Answer : in Triangle)
  452.                                                           is separate;
  453. begin
  454.    Compare( 3,  4,  5, Scalene);
  455.    Compare( 6,  3,  4, Scalene);
  456.    Compare( 4,  3,  6, Scalene);
  457.    Compare( 3,  3,  3, Equilateral);
  458.    Compare( 3,  3,  4, Isosceles);
  459.    Compare( 3,  4,  3, Isosceles);
  460.    Compare( 4,  3,  3, Isosceles);
  461.    Compare( 7,  7,  4, Isosceles);
  462.    Compare( 7,  4,  7, Isosceles);
  463.    Compare( 4,  7,  7, Isosceles);
  464.    Compare( 1,  1,  1, Equilateral);
  465.    Compare( 0,  4,  4, Not_a_Triangle);
  466.    Compare( 4,  0,  4, Not_a_Triangle);
  467.    Compare( 4,  4,  0, Not_a_Triangle);
  468.    Compare( 0,  4,  3, Not_a_Triangle);
  469.    Compare( 3,  0,  4, Not_a_Triangle);
  470.    Compare( 4,  3,  0, Not_a_Triangle);
  471.    Compare(-1,  4,  4, Not_a_Triangle);
  472.    Compare( 4, -1,  4, Not_a_Triangle);
  473.    Compare( 4,  4, -1, Not_a_Triangle);
  474.    Compare(-1,  4,  3, Not_a_Triangle);
  475.    Compare( 3, -1,  4, Not_a_Triangle);
  476.    Compare( 4,  3, -1, Not_a_Triangle);
  477.    Compare( 2,  4,  6, Not_a_Triangle);
  478.    Compare( 1,  3,  2, Not_a_Triangle);
  479.    Compare( 3,  1,  2, Not_a_Triangle);
  480.    Compare( 1,  2,  4, Not_a_Triangle);
  481.    Compare( 1,  4,  2, Not_a_Triangle);
  482.    Compare( 4,  1,  2, Not_a_Triangle);
  483.    Compare( 0,  0,  0, Not_a_Triangle);
  484.    Compare( 0,  0,  4, Not_a_Triangle);
  485.    Compare( 0,  4,  0, Not_a_Triangle);
  486.    Compare( 4,  0,  0, Not_a_Triangle);
  487.    Compare( 3,  3,  7, Not_a_Triangle);
  488.    Compare( 3,  7,  3, Not_a_Triangle);
  489.    Compare( 6,  3,  3, Not_a_Triangle);
  490.    Compare(-3, -4, -5, Not_a_Triangle);
  491.    if Passed then
  492.       Put_Line("Congratulations, you completed the assignment!");
  493.    end if;
  494. end Tritest;
  495.                            -- continued --
  496.  
  497.                                                                Page 11
  498.  
  499. separate (Tritest)
  500. procedure Compare(A, B, C: in Integer; Right_Answer : in Triangle) is
  501.    package Int_IO is new Integer_IO(Integer); use Int_IO;
  502.    package Tri_IO is new Enumeration_IO(Triangle); use Tri_IO;
  503.    My_Answer : Triangle := Tritype(A, B, C);
  504. begin
  505.    if My_Answer /= Right_Answer then
  506.       Put("Sides:");
  507.       Put(A, Width => 3);
  508.       Put(B, Width => 3);
  509.       Put(C, Width => 3);
  510.       Put("   My answer: ");
  511.       Put(My_Answer, Width => 14);
  512.       Put("   Right answer: ");
  513.       Put(Right_Answer);
  514.       New_Line;
  515.       Passed := False;
  516.    end if;
  517. end Compare;
  518.  
  519.                                                                Page 12
  520.  
  521.     STEPS FOR OUTSIDE ASSIGNMENT 2, EXERCISE IN ENUMERATION TYPES
  522.  
  523. 1.  Compile the test driver TRITEST.ADA.  Also, make a copy of the
  524.     dummy solution by typing COPY TRITYPE.DUM TRITYPE.ADA.  You need
  525.     do this step only once.
  526.  
  527. 2.  Edit TRITYPE.ADA to become your real solution.  You can skip this
  528.     step the first time through, to see error messages from the test
  529.     driver.
  530.  
  531. 3.  Compile your solution TRITYPE.ADA.  If the compiler finds errors,
  532.     go back to step 2.
  533.  
  534. 4.  Link with the name of the main program TRITEST.  Then execute.  If
  535.     the test driver displays error messages, go back to step 2.
  536.  
  537. 5.  When the message "Congratulations, you completed the assignment!"
  538.     is displayed, you'll have a chance to compare your solution with
  539.     ours.
  540.  
  541.                                                                Page 13
  542. NEXTDATE.ADA
  543. ------------
  544. with Text_IO; use Text_IO;
  545. procedure Nextdate is
  546.    type Month_Type is
  547.       (Jan, Feb, Mar, Apr, May, Jun, Jul, Aug, Sep, Oct, Nov, Dec);
  548.    subtype Day_Subtype is Integer range 1 .. 31;
  549.    type Date is
  550.       record
  551.          Day   : Day_Subtype;
  552.          Month : Month_Type;
  553.          Year  : Positive;
  554.       end record;
  555.    Passed : Boolean := True;
  556.    function Tomorrow(Today : in Date) return Date is separate;
  557.  
  558.    procedure Display (S : in String; D : in Date) is
  559.       package Int_IO is new Integer_IO(Integer); use Int_IO;
  560.    begin
  561.       Put(S);
  562.       Put(D.Day, Width => 3);
  563.       Put(" " & Month_Type'Image(D.Month));
  564.       Put(D.Year, Width => 5);
  565.       New_Line;
  566.    end Display;
  567.    procedure Compare(Today, Right_Answer : in Date) is
  568.       My_Answer : Date := Tomorrow(Today);
  569.    begin
  570.       if My_Answer /= Right_Answer then
  571.          Display("Today:       ", Today);
  572.          Display("My answer:   ", My_Answer);
  573.          Display("Right answer:", Right_Answer);
  574.          New_Line;
  575.          Passed := False;
  576.       end if;
  577.    end Compare;
  578. begin
  579.    Compare((12,Dec,1815), (13,Dec,1815)); -- ordinary date
  580.    Compare(( 3,Feb,1986), ( 4,Feb,1986)); -- ordinary date in Feb.
  581.    Compare((30,Jun,1981), ( 1,Jul,1981)); -- last day of 30-day month
  582.    Compare((30,Sep,3999), ( 1,Oct,3999)); -- last day of 30-day month
  583.    Compare((31,Mar,1876), ( 1,Apr,1876)); -- last day of 31-day month
  584.    Compare((31,Aug,1984), ( 1,Sep,1984)); -- last day of 31-day month
  585.    Compare((31,Dec,1966), ( 1,Jan,1967)); -- last day of year
  586.    Compare((28,Feb,1980), (29,Feb,1980)); -- leap year
  587.    Compare((28,Feb,1600), (29,Feb,1600)); -- century leap year
  588.    Compare((28,Feb,2200), ( 1,Mar,2200)); -- century non-leap year
  589.    Compare((28,Feb,1982), ( 1,Mar,1982)); -- non-leap year
  590.    Compare((29,Feb,1980), ( 1,Mar,1980)); -- leap day in leap year
  591.    if Passed then
  592.       Put_Line("Congratulations, you completed the assignment!");
  593.    end if;
  594. end Nextdate;
  595.  
  596.                                                                Page 14
  597.  
  598.          STEPS FOR OUTSIDE ASSIGNMENT 3, EXERCISE IN RECORDS
  599.  
  600. 1.  Compile the test driver NEXTDATE.ADA.  Also, make a copy of the
  601.     dummy solution by typing COPY TOMORROW.DUM TOMORROW.ADA.  You need
  602.     do this step only once.
  603.  
  604. 2.  Edit TOMORROW.ADA to become your real solution.  You can skip this
  605.     step the first time through, to see error messages from the test
  606.     driver.
  607.  
  608. 3.  Compile TOMORROW.ADA.  If the compiler finds errors, go back to
  609.     step 2.
  610.  
  611. 4.  Link with the name of the main program NEXTDATE.  Then execute.
  612.     If the test driver displays error messages, go back to step 2.
  613.  
  614. 5.  When the message "Congratulations, you completed the assignment!"
  615.     is displayed, you'll have a chance to compare your solution with
  616.     ours.
  617.  
  618.                                                                Page 15
  619.  
  620. FIBTEST.ADA
  621. -----------
  622.  
  623. with Text_IO; use Text_IO;
  624. procedure Fibtest is
  625.    Passed : Boolean := True;
  626.    function Fib(N : in Positive) return Positive is separate;
  627.    procedure Compare (N : in Positive; Right_Answer : in Positive) is
  628.       package Int_IO is new Integer_IO(Integer); use Int_IO;
  629.       My_Answer : Positive := Fib(N);
  630.    begin
  631.       if My_Answer /= Right_Answer then
  632.          Put("N:");  Put(N);
  633.          Put("          My answer:");  Put(My_Answer);
  634.          Put("          Right answer:");  Put(Right_Answer);
  635.          New_Line;
  636.          Passed := False;
  637.       end if;
  638.    end Compare;
  639. begin
  640.    Compare(1, 1);
  641.    Compare(2, 1);
  642.    Compare(3, 2);
  643.    Compare(4, 3);
  644.    Compare(5, 5);
  645.    Compare(6, 8);
  646.    Compare(7, 13);
  647.    Compare(10, 55);
  648.    Compare(15, 610);
  649.    Compare(20, 6765);
  650.    if Passed then
  651.       Put_Line("Congratulations, you completed the assignment!");
  652.    end if;
  653. end Fibtest;
  654.  
  655.                                                                Page 16
  656.  
  657.         STEPS FOR OUTSIDE ASSIGNMENT 4, EXERCISE IN RECURSION
  658.  
  659. 1.  Compile the test driver FIBTEST.ADA.  Also, make a copy of the
  660.     dummy solution by typing COPY FIB.DUM FIB.ADA.  You need do this
  661.     step only once.
  662.  
  663. 2.  Edit FIB.ADA to become your real solution.  You can skip this step
  664.     the first time through, to see error messages from the test
  665.     driver.
  666.  
  667. 3.  Compile FIB.ADA.  If the compiler finds errors, go back to step 2.
  668.  
  669. 4.  Link with the name of the main program FIBTEST.  Then execute.  If
  670.     the test driver displays error messages, go back to step 2.
  671.  
  672. 5.  When the message "Congratulations, you completed the assignment!"
  673.     is displayed, you'll have a chance to compare your solution with
  674.     ours.
  675.  
  676.                                                                Page 17
  677. SIMPLIFIED SPECIFICATION FOR TEXT_IO
  678. ------------------------------------
  679. package Text_IO is
  680.    type File_Type is limited private;
  681.  
  682.    type File_Mode is (In_File, Out_File);  -- Ada 9X adds Append_File.
  683.    type Count is ... (a user-defined type similar to Integer);
  684.    Status_Error, Mode_Error, Name_Error, End_Error : exception;
  685.  
  686.    procedure Create      (File : in out File_Type;
  687.                           Mode : in File_Mode := Out_File;
  688.                           Name : in String);
  689.  
  690.    procedure Open        (File : in out File_Type;
  691.                           Mode : in File_Mode;
  692.                           Name : in String);
  693.  
  694.    procedure Close       (File : in out File_Type);
  695.    procedure Delete      (File : in out File_Type);
  696.    procedure New_Line    (Spacing : in Count := 1);
  697.    procedure New_Line    (File : in File_Type;
  698.                           Spacing : in Count := 1);
  699.    procedure Skip_Line   (Spacing : in Count := 1);
  700.    procedure Skip_Line   (File : in File_Type;
  701.                           Spacing : in Count := 1);
  702.    function  End_Of_File (File : in File_Type) return Boolean;
  703.    procedure Put         (Item : in Character);
  704.    procedure Put         (File : in File_Type; Item : in Character);
  705.    procedure Get         (Item : out Character);
  706.    procedure Get         (File : in File_Type; Item : out Character);
  707.    procedure Put         (Item : in String);
  708.    procedure Put         (File : in File_Type; Item : in String);
  709.    procedure Put_Line    (Item : in String);
  710.    procedure Put_Line    (File : in File_Type; Item : in String);
  711.    procedure Get_Line    (Item : out String; Last : out Natural);
  712.    procedure Get_Line    (File : in File_Type;
  713.                           Item : out String;
  714.                           Last : out Natural);
  715.    generic
  716.       type Num is range <>;
  717.    package Integer_IO is
  718.       procedure Get (Item : out Num);
  719.       procedure Get (File : in File_Type; Item : out Num);
  720.       procedure Put (Item  : in Num;
  721.                      Width : in Integer := ...;
  722.                      Base  : in Integer := 10);
  723.       procedure Put (File  : in File_Type;
  724.                      Item  : in Num;
  725.                      Width : in Integer := ...;
  726.                      Base  : in Integer := 10);
  727.    end Integer_IO;
  728.  
  729.                            -- continued --
  730.  
  731.                                                                Page 18
  732.  
  733.    generic
  734.       type Num is digits <>;
  735.    package Float_IO is
  736.       procedure Get (Item : out Num);
  737.       procedure Get (File : in File_Type; Item : out Num);
  738.       procedure Put (Item : in Num;
  739.                      Fore : in Integer := 2;
  740.                      Aft  : in Integer := ...;
  741.                      Exp  : in Integer := 3);
  742.       procedure Put (File : in File_Type;
  743.                      Item : in Num;
  744.                      Fore : in Integer := 2;
  745.                      Aft  : in Integer := ...;
  746.                      Exp  : in Integer := 3);
  747.    end Float_IO;
  748.  
  749.    generic
  750.       type Enum is (<>);
  751.    package Enumeration_IO is
  752.       procedure Get (Item : out Enum);
  753.       procedure Get (File : in File_Type; Item : out Enum);
  754.       procedure Put (Item : in Enum; Width : in Integer := 0);
  755.       procedure PUT (File : in File_Type;
  756.                      Item : in Enum; Width : in Integer := 0);
  757.    end Enumeration_IO;
  758.  
  759. private
  760.  
  761.    type File_Type is ... (implementation dependent);
  762.  
  763. end Text_IO;
  764.  
  765.                                                                Page 19
  766.  
  767. Program to copy a simple text file:
  768. -----------------------------------
  769.  
  770. with Text_IO; use Text_IO;
  771. procedure Filecopy Is
  772.    F1, F2 : File_Type;
  773.    S      : String(1 .. 80);
  774.    Len    : Integer;
  775. begin
  776.    Put("Input file: ");  Get_Line(S, Len);
  777.    Open(File => F1, Mode => In_File, Name => S(1 .. Len));
  778.    Put("Output file: ");  Get_Line(S, Len);
  779.    Create(File => F2, Mode => Out_File, Name => S(1 .. Len));
  780.    while not End_Of_File(F1) loop
  781.       Get_Line(F1, S, Len);
  782.       Put_Line(F2, S(1 .. Len));
  783.    end loop;
  784.    Close(F1);
  785.    Close(F2);
  786. end Filecopy;
  787.  
  788.  
  789.  
  790. Function to test if a text file exists:
  791. ---------------------------------------
  792.  
  793. with Text_IO; use Text_IO;
  794. function Exists(File_Name : in String) return Boolean Is
  795.    F      : File_Type;
  796.    Answer : Boolean := True;
  797. begin
  798.    begin
  799.       Open(F, In_File, File_Name);
  800.       Close(F);
  801.    exception
  802.       when Name_Error => Answer := False;
  803.    end;
  804.    return Answer;
  805. end Exists;
  806.  
  807.                                                                Page 20
  808.  
  809.                  REQUIREMENTS FOR THE PROGRAM LEDIT
  810.  
  811.      This assignment will give you practice in writing a program of
  812. greater complexity than the previous programs you've written.  Imagine
  813. that your screen editor is unavailable to a particular user, perhaps
  814. because the user is dialing your computer from a remote location, and
  815. your screen editor writes directly to the screen.  You want to write a
  816. very simple line editor, LEDIT, that could be used in such
  817. circumstances.  While your computer already has a line editor called
  818. EDLIN, it's difficult to learn to use.  LEDIT will take almost no
  819. effort to learn.  The only commands are LIST and EXIT!  LEDIT edits by
  820. means of line numbers, similar to early versions of Basic.
  821.      The user begins each typed line of text with a line number from 1
  822. to 29999.  Line numbers must be integers.  We chose the upper limit
  823. 29999 so that the simple type Integer could be used - in any
  824. implementation of Ada.   Regardless of the order in which lines are
  825. typed, LEDIT maintains a linked list of lines in order by number.
  826. Also, line numbers may be preceded by any number of spaces.  For
  827. example, if the user types
  828.  
  829. 40 -- This is a comment.
  830.    20 begin
  831. 10 with Text_IO; use Text_IO;
  832.       30 end Add;
  833.  
  834. and then types LIST, the editor will type
  835.  
  836.    10 with Text_IO; use Text_IO;
  837.    20 begin
  838.    30 end Add;
  839.    40 -- This is a comment.
  840.  
  841.      To INSERT lines, the user merely types lines with intermediate
  842. line numbers.  For example, if the user types
  843.  
  844. 15 procedure Hello is
  845.  
  846. and then types LIST, LEDIT will type
  847.  
  848.    10 with Text_IO; use Text_IO;
  849.    15 procedure Hello is
  850.    20 begin
  851.    30 end Add;
  852.    40 -- This is a comment.
  853.  
  854.      To REPLACE an existing line, the user merely types a line with
  855. the same line number as the line to be replaced.  For example, if
  856.  
  857. 15 procedure Add is
  858. LIST
  859.  
  860.                            -- continued --
  861.  
  862.                                                                Page 21
  863.  
  864. is typed, LEDIT would then show
  865.  
  866.    10 with Text_IO; use Text_IO;
  867.    15 procedure Add is
  868.    20 begin
  869.    30 end Add;
  870.    40 -- This is a comment.
  871.  
  872.      Finally, to DELETE a line, the user merely types the number of
  873. the line to be deleted, followed immediately by a carriage return.
  874. Typing
  875.  
  876. 40
  877. LIST
  878.  
  879. would then produce
  880.  
  881.    10 with Text_IO; use Text_IO;
  882.    15 procedure Add is
  883.    20 begin
  884.    30 end Add;
  885.  
  886.      Thus the user can INSERT, REPLACE, and DELETE lines, all by line
  887. numbers, without learning any commands.  Note that in this simple
  888. editor there is no "cursor" and no "current line."
  889.      The space is not required after the line number.  These two lines
  890. have exactly the same effect:
  891.  
  892. 20 begin
  893. 20begin
  894.  
  895. Of course, if the text of the line begins with a digit, a space will
  896. be required to separate it from the line number.  In any event, LEDIT
  897. always leaves one blank space after the line number when LISTing, for
  898. readability.  It always allows exactly five spaces for the line number
  899. itself.
  900.      However, any EXTRA spaces typed after the line number are
  901. significant.  The three lines below each contain three EXTRA spaces
  902. after the line number, for a total of four spaces.
  903.  
  904. 24    Put(2 + 2);
  905. 26    New_LiNe;
  906. 18    package My_Int_IO is new Integer_IO(Integer); use My_Int_IO;
  907.  
  908. They have the effect of indenting the text three spaces.  LIST now
  909. shows
  910.  
  911.  
  912.                            -- continued --
  913.  
  914.                                                                Page 22
  915.  
  916.    10 with Text_IO; use Text_IO;
  917.    15 procedure Add is
  918.    18    package My_Int_IO is new Integer_IO(Integer); use My_Int_IO;
  919.    20 begin
  920.    24    Put(2 + 2);
  921.    26    New_Line;
  922.    30 end Add;
  923.  
  924.      Although typing a line number followed immediately by a carriage
  925. return deletes a line (if there is a line by that number), typing a
  926. line number followed by a single space causes an empty line to be
  927. introduced into the file.  For example, typing 12 followed by a single
  928. space and a carriage return would then cause LIST to type
  929.  
  930.    10 with Text_IO; use Text_IO;
  931.    12
  932.    15 procedure Add is
  933.    18    package My_Int_IO is new Integer_IO(Integer); use My_Int_IO;
  934.    20 begin
  935.    24    Put(2 + 2);
  936.    26    New_Line;
  937.    30 end Add;
  938.  
  939.      When LEDIT is run, it prompts for the names of the input and
  940. output files.  If the input file exists, LEDIT displays "File found"
  941. and reads the file into its linked list, assigning line numbers
  942. starting with 10 and incrementing by 10.  If the file does not exist,
  943. LEDIT displays "File not found," and the linked list is initially
  944. empty.  In any event, LEDIT creates an output file.  When the EXIT
  945. command is given, LEDIT writes the contents of the linked list to the
  946. output file.  In doing so, LEDIT removes the line numbers and the
  947. first blank after each line number.
  948.      In the example above, let's assume that the user typed ADD.ADA
  949. for an output file name.  When the user types EXIT, the new file
  950. ADD.ADA created by LEDIT will contain:
  951.  
  952. with Text_IO; use Text_IO;
  953.  
  954. procedure Add is
  955.    package My_Int_IO is new Integer_IO(Integer); use My_Int_IO;
  956. begin
  957.    Put(2 + 2);
  958.    New_Line;
  959. end Add;
  960.  
  961. (Note that the file contains one empty line.)  Your program is not
  962. allowed to add any trailing blanks of its own in the output file.  If
  963. the user again runs LEDIT and specifies ADD.ADA as an input file, the
  964. editor will type "File found" and read the file.  LIST will then show
  965.  
  966.  
  967.                            -- continued --
  968.  
  969.                                                                Page 23
  970.  
  971.    10 with Text_IO; use Text_IO;
  972.    20
  973.    30 procedure Add is
  974.    40    package My_Int_IO is new Integer_IO(Integer); use My_Int_IO;
  975.    50 begin
  976.    60    Put(2 + 2);
  977.    70    New_Line;
  978.    80 end Add;
  979.  
  980. When the user EXITs, the new file will contain modified text.  The old
  981. file will still be present until it is deleted.
  982.      The two commands LIST and EXIT must be accepted in either upper
  983. or lower case, but for simplicity, they need not be accepted in a
  984. mixture of cases.  They may be preceded by any number of spaces.  The
  985. LIST command must be accepted in any of the following forms:
  986.  
  987. LIST            (Lists all lines, if any, otherwise does nothing.)
  988. list 30         (Lists line 30, if it exists.)
  989. list 25 - 35    (Lists all lines between 25 and 35 inclusive, if any.)
  990. LIST - 35       (Lists all lines numbered 35 or less, if any.)
  991. list 25 -       (Lists all lines numbered 25 or more, if any.)
  992.  
  993. Furthermore, all spaces are optional in the LIST command provided that
  994. LIST is written solid, so that LIST25-35 is equivalent to the third
  995. example above.  Any other forms of LIST should be flagged as an error.
  996. In particular, all of these should give error messages:
  997.  
  998. LIST -
  999. list 2A
  1000. LIST 30 - 50 -
  1001. list 30 - -50
  1002. list 30-A
  1003. LIST XYZ
  1004.  
  1005.      The EXIT command must stand alone; unlike LIST, EXIT is never
  1006. followed by anything.  Except for the LIST and EXIT commands, every
  1007. line typed must begin with a number between 1 and 29999.  (Of course,
  1008. the user should be able to type just a carriage return with no
  1009. effect.)  LEDIT should check that line numbers are in range when adding
  1010. or replacing lines.  The LIST command need not check the range of the
  1011. line numbers, because it should be impossible to create lines with
  1012. improper numbers.  Your program need not handle input files so long
  1013. that 29999 would be exceeded when it assigns line numbers starting at
  1014. 10 with an increment of 10.
  1015.      Your LEDIT must prompt for input and output file names at the
  1016. start, and it may display a prompt for each line that the user types.
  1017. You may assume some maximum length for an input line (e.g., 80), and
  1018. assume that no file will have lines longer than the maximum.  You may
  1019. also assume that no file will have special characters like form feeds.
  1020.  
  1021.  
  1022.                            -- continued --
  1023.  
  1024.                                                                Page 24
  1025.  
  1026.      For simplicity, there's no way to edit a line except by retyping
  1027. it.  Also, there's no way to copy or move a line or a block of lines,
  1028. and no way to delete a block of lines except one line at a time.
  1029. There's no RENUMBER command.  The user can renumber the entire file
  1030. starting at 10 with an increment of 10 by EXITing and then rerunning
  1031. LEDIT.  There's no AUTO command to make the editor type the line
  1032. numbers automatically while text is being typed by the user, and
  1033. there's no means of recovering from a system crash that occurs during
  1034. an edit.  Additionally, there's no way to search for a string, or
  1035. replace one string with another.  These features would all be
  1036. desirable, but we feel that Outside Assignment 5 is challenging as it
  1037. stands.
  1038.      You're encouraged to use Ada's "separate" compilation feature, so
  1039. that you don't have to recompile the entire program when developing a
  1040. module.
  1041.      As a point of reference, our solution to this assignment consists
  1042. of about 180 lines of code on four pages.  If you have any questions
  1043. about what LEDIT should do, you can compile and run our solution,
  1044. which is in LEDIT.ANS.
  1045.      The following declarations are offered by way of suggestion only,
  1046. and you should use them only if you feel comfortable with them:
  1047.  
  1048.      Max_Length : constant Integer := 80;
  1049.      type Text is
  1050.         record
  1051.            Len : Integer range 0 .. Max_Length;
  1052.            Val : String(1 .. Max_Length);
  1053.         end record;
  1054.  
  1055.      type Link;
  1056.      type P is access Link;
  1057.      type Link is
  1058.         record
  1059.            Num  : Positive;
  1060.            Line : Text;
  1061.            Next : P;
  1062.         end record;
  1063.  
  1064.      function Str(T : in Text) return String;
  1065.  
  1066.      In our solution, we used type Text as above.  However, we didn't
  1067. write a Text_Handler package, because it didn't seem to be needed.  We
  1068. used a one-page main program with several "separate" subprograms.
  1069.  
  1070.                                                                Page 25
  1071.  
  1072.     STEPS FOR OUTSIDE ASSIGNMENT 5, WRITING A SIMPLE LINE EDITOR
  1073.  
  1074. 1.  Carefully read the requirements starting on page 20 of these
  1075.     notes.  Take your time.
  1076.  
  1077. 2.  Write the Ada code, compile, and link.  Call the main program
  1078.     LEDIT.  If you have any questions about what LEDIT should do, you
  1079.     can compile and run our solution, which is in LEDIT.ANS.
  1080.  
  1081. 3.  Refer to pages 26-28 of these notes for instructions on testing
  1082.     your line editor.  If any tests are failed, go back to step 2.
  1083.  
  1084. 4.  When all the tests are passed, you've completed the assignment and
  1085.     will have a chance to compare your solution with ours.
  1086.  
  1087.                                                                Page 26
  1088.                           HOW TO TEST LEDIT
  1089.  
  1090. 1.  Run LEDIT and give the name of an input file that doesn't exist.
  1091. LEDIT should say "File not found."  Give another name of a file that
  1092. doesn't exist for an output file.
  1093.  
  1094. 2.  Type "LIST" (without the quotes) to make sure that LEDIT can
  1095. handle the LIST command when no text has been entered.
  1096.  
  1097. 3.  Type "EXI".  The program should NOT exit.  If it exits, it's
  1098. probably because the "T" was left in the input buffer from the LIST
  1099. command.  Your program is checking the first four characters of the
  1100. input buffer without checking the length of the typed command.
  1101.  
  1102. 4.  Type "ABC".  The program should display a message about an illegal
  1103. or unrecognized command, or syntax error.
  1104.  
  1105. 5.  Type "0X" (zero followed by X).  The program should reject this
  1106. line, displaying a message about an invalid line number.  Type "0 X".
  1107. The same thing should happen.  Try "30000X", then "30000 X", and then
  1108. "3000000000 X".  The program should reject these, as well.
  1109.  
  1110. 6.  Type "-1 X" and "-1X".  The program should reject these lines,
  1111. displaying a message either about an unrecognized command (or syntax
  1112. error), or an invalid line number.
  1113.  
  1114. 7.  Type a simple carriage return.  There should be no effect, except
  1115. for any prompt being repeated.
  1116.  
  1117. 8.  Type the following exactly as shown.  Note that lines 1000 and 100
  1118. each contain four spaces:
  1119.  
  1120. 30 X
  1121. 1 The
  1122. 29999 ZZZZZZZZ
  1123. 1000    used
  1124. 100    is
  1125. 10000 to test
  1126.    30file --
  1127. 1 This
  1128.     29999 LEDIT.
  1129.  
  1130. 9.  Type "list".  You should see the following, lined up exactly as
  1131. shown.  There should be exactly five spaces for the line numbers.
  1132.  
  1133.     1 This
  1134.    30 file --
  1135.   100    is
  1136.  1000    used
  1137. 10000 to test
  1138. 29999 LEDIT.
  1139.                            -- continued --
  1140.  
  1141.                                                                Page 27
  1142.  
  1143. 10.  Try a line of text beginning with a number: "20000 123 45".  Then
  1144. type "   LIST" with three leading spaces.  You should see
  1145.  
  1146.     1 This
  1147.    30 file --
  1148.   100    is
  1149.  1000    used
  1150. 10000 to test
  1151. 20000 123 45
  1152. 29999 LEDIT.
  1153.  
  1154. 11.  Insert an empty line by typing "15000 ".  Then type "LIST".  You
  1155. should see
  1156.  
  1157.     1 This
  1158.    30 file --
  1159.   100    is
  1160.  1000    used
  1161. 10000 to test
  1162. 15000
  1163. 20000 123 45
  1164. 29999 LEDIT.
  1165.  
  1166. 12.  Type "EXIT ABC".  LEDIT should display a error message and NOT
  1167. exit.  The requirements say that the EXIT command must stand alone.
  1168.  
  1169. 13.  Type "   exit".  LEDIT should exit, and you should have a new
  1170. file with the output file name you gave in step 1.  Type the file with
  1171. the TYPE command.  You should see exactly this, starting in column 1:
  1172.  
  1173. This
  1174. file --
  1175.    is
  1176.    used
  1177. to test
  1178.  
  1179. 123 45
  1180. LEDIT.
  1181.  
  1182. 14.  Run LEDIT again.  Use for an input file the name of the OUTPUT
  1183. file you used in step 1.  LEDIT should say "File found."  Choose yet
  1184. another name for the output file and type "list".  You should see:
  1185.  
  1186.    10 This
  1187.    20 file --
  1188.    30    is
  1189.    40    used
  1190.    50 to test
  1191.    60
  1192.    70 123 45
  1193.    80 LEDIT.
  1194.                            -- continued --
  1195.  
  1196.                                                                Page 28
  1197.  
  1198. 15.  Type "  LIST 30".  You should see only line 30.  Type
  1199. "list25-45".  You should see only lines 30 and 40.  Type "LIST  - 40".
  1200. You should see lines 10 through 40.  Type "list35 -".  You should see
  1201. lines 40 through 80.  Type "list 15".  The program should either do
  1202. nothing or display a message that line 15 doesn't exist.  Try
  1203. "list 30000" and "list 3000000000".  Again, the program should either
  1204. do nothing or display an error message.  Now type "list" and check
  1205. that the result is the same as in step 14.
  1206.  
  1207. 16.  LEDIT should display an error message for each of the following:
  1208.  
  1209. LIST -
  1210. list 2A
  1211. list 30 - 50 -
  1212. list 30 - -50
  1213.    list 30-A
  1214. LIST XYZ
  1215.  
  1216. 17.  Type "70" to delete line 70.  Type "LIST".  You should see
  1217.  
  1218.    10 This
  1219.    20 file --
  1220.    30    is
  1221.    40    used
  1222.    50 to test
  1223.    60
  1224.    80 LEDIT.
  1225.  
  1226. 18.  Delete line 60.  Do not list.  Now delete line 80 and list.  You
  1227. should see
  1228.  
  1229.    10 This
  1230.    20 file --
  1231.    30    is
  1232.    40    used
  1233.    50 to test
  1234.  
  1235. 19.  Delete line 10 and list.  You should see lines 20 through 50
  1236. above.  Delete line 50 and list.  You should see lines 20 through 40.
  1237. Delete line 30 and list.  You should see lines 20 and 40.  Delete line
  1238. 40 and list.  You should see only line 20.  Delete line 20 and list.
  1239. The result should be the same as in step 2.  Type "EXIT".
  1240.  
  1241. 20.  If your program passed all these tests, sincere congratulations!
  1242. You've completed a difficult assignment.  We hope that you feel
  1243. comfortable with Ada now.  If you like, you can compare your solution
  1244. with ours, starting on page 29 of these notes.  When you go back to
  1245. ADA-TUTR, you'll learn to write your own generic packages, procedures,
  1246. and functions.
  1247.  
  1248.                                                                Page 29
  1249. LEDIT.ANS
  1250. ---------
  1251.  
  1252. -- Our solution to Outside Assignment 5:
  1253. with Text_IO; use Text_IO;
  1254. procedure Ledit is
  1255.    Max_Length      : constant := 80;
  1256.    Max_Line_Number : constant := 29_999;
  1257.    type Text is
  1258.       record
  1259.          Len : Integer range 0 .. Max_Length := 0;
  1260.          Val : String(1 .. Max_Length);
  1261.       end record;
  1262.    type Link;
  1263.    type P is access Link;
  1264.    type Link is
  1265.       record
  1266.          Num  : Positive;
  1267.          Line : Text;
  1268.          Next : P;
  1269.       end record;
  1270.    Head            : P := new Link;
  1271.    Temp            : P;
  1272.    Input_File      : File_Type;
  1273.    Output_File     : File_Type;
  1274.    Input           : Text;
  1275.    Finished        : Boolean := False;
  1276.    Line_Num        : Natural := 10;
  1277.  
  1278.    function  Str(T : in Text) return String is separate;
  1279.    procedure Read_Input_File is separate;
  1280.    procedure Do_Command is separate;
  1281. begin
  1282.    Put("Input file: ");  Get_Line(Input.Val, Input.Len);
  1283.    Read_Input_File;
  1284.    Put("Output file: ");  Get_Line(Input.Val, Input.Len);
  1285.    Create(Output_File, Name => Str(Input));
  1286.  
  1287.    -- Get and process commands.
  1288.    while not Finished loop
  1289.       Put("> ");  Get_Line(Input.Val, Input.Len);
  1290.       Do_Command;
  1291.    end loop;
  1292.  
  1293.    -- Write the output file.
  1294.    Temp := Head.Next;     -- Skip unused link at start of linked list.
  1295.    while Temp /= null loop
  1296.       Put_Line(Output_File, Str(Temp.Line));    -- Write line of text.
  1297.       Temp := Temp.Next;                             -- Get next link.
  1298.    end loop;
  1299.    Close(Output_File);
  1300. end Ledit;
  1301.                            -- continued --
  1302.  
  1303.                                                                Page 30
  1304. separate (Ledit)
  1305. function Str(T : in Text) return String is
  1306. begin
  1307.    return T.Val(1 .. T.Len);
  1308. end Str;
  1309.  
  1310. separate (Ledit)
  1311. procedure Read_Input_File is
  1312. begin   -- If the input file exists, display a message and read it in.
  1313.    Open(Input_File, In_File, Str(Input));
  1314.    Put_Line("File found.");
  1315.    Temp := Head;
  1316.    while not End_Of_File(Input_File) loop
  1317.       Get_Line(Input_File, Input.Val, Input.Len);      -- Read a line.
  1318.       Temp.Next := new Link'(Line_Num, Input, null);   -- Add to list.
  1319.       Temp := Temp.Next;              -- Advance pointer to next link.
  1320.       Line_Num := Line_Num + 10;
  1321.    end loop;
  1322.    Close(Input_File);
  1323. exception  -- If the input file doesn't exist, just display a message.
  1324.    when Name_Error => Put_Line("File not found.");
  1325. end Read_Input_File;
  1326.  
  1327. separate (Ledit)
  1328. procedure Do_Command is
  1329.    procedure Delete_First_Character(T : in out Text) is separate;
  1330.    procedure Get_Leading_Integer(N : out Natural) is separate;
  1331.    procedure Strip_Leading_Spaces_From_Input is separate;
  1332.    procedure Add_Delete_Replace_Line is separate;
  1333.    procedure List is separate;
  1334. begin
  1335.    Strip_Leading_Spaces_From_Input;
  1336.    if Str(Input) = "exit" or Str(Input) = "EXIT" then
  1337.       Finished := True;
  1338.    elsif Input.Len >= 4 and (Input.Val(1 .. 4) = "list" or
  1339.                                Input.Val(1 .. 4) = "LIST") then
  1340.       List;
  1341.    elsif Input.Len > 0 and Input.Val(1) not in '0' .. '9' then
  1342.       Put_Line("Unrecognized command.");
  1343.    elsif Input.Len > 0 then
  1344.       Get_Leading_Integer(Line_Num);
  1345.       if Line_Num not in 1 .. Max_Line_Number then
  1346.          Put_Line("Illegal line number.");
  1347.       else
  1348.          Add_Delete_Replace_Line;
  1349.       end if;
  1350.    end if;
  1351. exception
  1352.    when Numeric_Error | Constraint_Error =>
  1353.       Put_Line("Line number too large.");
  1354. end Do_Command;
  1355.  
  1356.                            -- continued --
  1357.  
  1358.                                                                Page 31
  1359.  
  1360. separate (Ledit.Do_Command)
  1361. procedure Add_Delete_Replace_Line is
  1362.    Inp : Text := Input;
  1363. begin
  1364.    if Inp.Len > 0 and Inp.Val(1) = ' ' then  -- Treat "9x" like "9 x".
  1365.       Delete_First_Character(Inp);
  1366.    end if;
  1367.    Temp := Head;     -- Find where this number belongs in linked list.
  1368.    while Temp /= null and then Temp.Next /= null and then
  1369.                                Temp.Next.Num <= Line_Num loop
  1370.       if Temp.Next.Num = Line_Num then
  1371.          Temp.Next := Temp.Next.Next;                  -- Delete line.
  1372.       else
  1373.          Temp := Temp.Next;           -- Advance to next link in list.
  1374.       end if;
  1375.    end loop;
  1376.    if Input.Len > 0 then                                  -- Add line.
  1377.       Temp.Next := new Link'(Line_Num, Inp, Temp.Next);
  1378.    end if;
  1379. end Add_Delete_Replace_Line;
  1380.  
  1381. separate (Ledit.Do_Command)
  1382. procedure Delete_First_Character(T : in out Text) is
  1383. begin
  1384.    T.Val(1 .. T.Len - 1) := T.Val(2 .. T.LEN);
  1385.    T.Len := T.Len - 1;
  1386. end Delete_First_Character;
  1387.  
  1388. separate (Ledit.Do_Command)
  1389. procedure Get_Leading_Integer(N : out Natural) is
  1390.    Ans: Integer := 0;
  1391. begin
  1392.    while Input.Len > 0 and Input.Val(1) in '0' .. '9' loop
  1393.       Ans := Ans*10 + Character'Pos(Input.Val(1)) -Character'Pos('0');
  1394.       Delete_First_Character(Input);
  1395.    end loop;
  1396.    N := Ans;
  1397. end Get_Leading_Integer;
  1398.  
  1399. separate (Ledit.Do_Command)
  1400. procedure Strip_Leading_Spaces_From_Input is
  1401. begin
  1402.    while Input.Len > 0 and Input.Val(1) = ' ' loop
  1403.       Delete_First_Character(Input);
  1404.    end loop;
  1405. end Strip_Leading_Spaces_From_Input;
  1406.  
  1407.  
  1408.                            -- continued --
  1409.  
  1410.                                                                Page 32
  1411.  
  1412. separate (Ledit.Do_Command)
  1413. procedure List is
  1414.    package IIO is new Integer_IO(Integer); use IIO;
  1415.    Start, Finish : Natural;
  1416.    Valid         : Boolean := True;
  1417. begin
  1418.    Input.Len := Input.Len - 4;      -- Delete the name of the command.
  1419.    Input.Val(1 .. Input.Len) := Input.Val(5 .. Input.Len + 4);
  1420.    Strip_Leading_Spaces_From_Input;
  1421.    if Input.Len = 0 then          -- For "LIST" alone, list all lines.
  1422.       Start := 0;
  1423.       Finish := Max_Line_Number + 1;
  1424.    else
  1425.       Get_Leading_Integer(Start);          -- Get number after "LIST".
  1426.       Strip_Leading_Spaces_From_Input;
  1427.       if Input.Len = 0 then         -- For "LIST n", list only line n.
  1428.          Finish := Start;
  1429.       elsif Input.Val(1) /= '-' then        -- Else "-" must follow n.
  1430.          Valid := False;
  1431.       else
  1432.          Delete_First_Character(Input);             -- Delete the "-".
  1433.          Strip_Leading_Spaces_From_Input;
  1434.          Get_Leading_Integer(Finish);         -- Get number after "-".
  1435.          Strip_Leading_Spaces_From_Input;
  1436.          if Finish = 0 and Start = 0 then     -- "LIST -" isn't valid.
  1437.             Valid := False;
  1438.          elsif Finish = 0 then  -- For "LIST n -", list n through end.
  1439.             Finish := Max_Line_Number + 1;
  1440.          end if;
  1441.          Valid := Valid  and  Input.Len = 0;   -- No trailing garbage.
  1442.       end if;
  1443.    end if;
  1444.    if not Valid then
  1445.       Put_Line("Illegal syntax for LIST.");
  1446.    else
  1447.       Temp := Head.Next;  -- Skip unused link at start of linked list.
  1448.       while Temp /= null and then Temp.Num <= Finish loop
  1449.          if Temp.Num >= Start then
  1450.             Put(Temp.Num, Width => 5);     -- Display line #, width 5.
  1451.             Put_Line(' ' & Str(Temp.Line));   -- Display text of line.
  1452.          end if;
  1453.          Temp := Temp.Next;                          -- Get next link.
  1454.       end loop;
  1455.    end if;
  1456. exception
  1457.    when Numeric_Error | Constraint_Error =>
  1458.       Put_Line("Line number too large in List.");
  1459. end List;
  1460.  
  1461.                                                                Page 33
  1462.  
  1463. TASKING.DUM
  1464. -----------
  1465.  
  1466. with text_io, calendar; use text_io, calendar;
  1467. procedure tasking is
  1468.    interval        : constant duration := 5.0;
  1469.    total_intervals : constant positive := 9;
  1470.    start_time      : constant time := clock;
  1471.    quitting_time   : constant time := start_time +
  1472.                                              total_intervals*interval;
  1473.    next_time       : time := start_time;
  1474.    task type tick is
  1475.       entry make_noise;
  1476.       entry shutdown;
  1477.    end tick;
  1478.    t               : tick;
  1479.    task body tick is
  1480.       quit : boolean := false;
  1481.    begin
  1482.       while not quit loop
  1483.          select
  1484.             accept make_noise do
  1485.                put_line("Tick!");
  1486.             end make_noise;
  1487.          or
  1488.             accept shutdown;
  1489.             quit := true;
  1490.          end select;
  1491.       end loop;
  1492.    end tick;
  1493. begin
  1494.    while next_time < quitting_time loop
  1495.       t.make_noise;
  1496.       next_time := next_time + interval;
  1497.       put_line("(5-second delay)"); delay next_time - clock;
  1498.    end loop;
  1499.    t.shutdown;
  1500. end tasking;
  1501.  
  1502.                                                                Page 34
  1503.  
  1504.          STEPS FOR OUTSIDE ASSIGNMENT 6, EXERCISE IN TASKING
  1505.  
  1506. 1.  Make a copy of TASKING.DUM by typing COPY TASKING.DUM TASKING.ADA.
  1507.     Compile, link, and execute the program to make sure it displays
  1508.     "Tick!" nine times, with a 5-second delay after each "Tick."
  1509.  
  1510. 2.  Edit TASKING.ADA to become your solution.  Make your changes in
  1511.     upper case.
  1512.  
  1513. 3.  Compile TASKING.ADA, link, and execute.
  1514.  
  1515. 4.  Compare your output with page 35 of these notes.  If there are any
  1516.     errors, go back to step 2.
  1517.  
  1518. 5.  When your output agrees with these notes, you've finished the
  1519.     assignment and will have a chance to compare your solution with
  1520.     ours.
  1521.  
  1522.                                                                Page 35
  1523.  
  1524.       OUTPUT FROM TASKING.EXE AFTER MODIFICATION OF TASKING.ADA
  1525.  
  1526. C>tasking
  1527. Task number 1 is starting.
  1528. Task number 2 is starting.
  1529. Task number 3 is starting.
  1530. (5-second delay)
  1531. (5-second delay)
  1532. Task number 1 is starting.
  1533. (5-second delay)
  1534. Task number 2 is starting.
  1535. (5-second delay)
  1536. Task number 1 is starting.
  1537. Task number 3 is starting.
  1538. (5-second delay)
  1539. (5-second delay)
  1540. Task number 1 is starting.
  1541. Task number 2 is starting.
  1542. (5-second delay)
  1543. (5-second delay)
  1544. Task number 1 is starting.
  1545. Task number 3 is starting.
  1546. (5-second delay)
  1547.  
  1548. C>
  1549.  
  1550.                                                                Page 36
  1551.  
  1552. TASKING.ANS
  1553. -----------
  1554.  
  1555. -- Our solution to Outside Assignment 6:
  1556. with text_io, calendar; use text_io, calendar;
  1557. procedure tasking is
  1558.    interval        : constant duration := 5.0;
  1559.    total_intervals : constant positive := 9;
  1560.    start_time      : constant time := clock;
  1561.    quitting_time   : constant time := start_time +
  1562.                                              total_intervals*interval;
  1563.    next_time       : time := start_time;
  1564.    task type tick is
  1565.       ENTRY IDENTIFY(TASK_NUMBER : IN NATURAL);
  1566.       entry shutdown;
  1567.    end tick;
  1568.    T               : ARRAY(1 .. 3) OF TICK;
  1569.    PERIOD          : CONSTANT ARRAY(T'RANGE) OF POSITIVE := (2, 3, 4);
  1570.    TIMER           : ARRAY(T'RANGE) OF NATURAL := (OTHERS => 0);
  1571.    task body tick is
  1572.       quit : boolean := false;
  1573.    begin
  1574.       while not quit loop
  1575.          select
  1576.             ACCEPT IDENTIFY(TASK_NUMBER : IN NATURAL) DO
  1577.                PUT_LINE("Task number" & INTEGER'IMAGE(TASK_NUMBER) &
  1578.                     " is starting.");
  1579.             END IDENTIFY;
  1580.          or
  1581.             accept shutdown;
  1582.             quit := true;
  1583.          end select;
  1584.       end loop;
  1585.    end tick;
  1586. begin
  1587.    while next_time < quitting_time loop
  1588.       FOR I IN T'RANGE LOOP
  1589.          IF TIMER(I) = 0 THEN
  1590.             T(I).IDENTIFY(I);
  1591.             TIMER(I) := PERIOD(I);
  1592.          END IF;
  1593.          TIMER(I) := TIMER(I) - 1;
  1594.       END LOOP;
  1595.       next_time := next_time + interval;
  1596.       put_line("(5-second delay)"); delay next_time - clock;
  1597.    end loop;
  1598.    FOR I IN T'RANGE LOOP
  1599.       T(I).SHUTDOWN;
  1600.    END LOOP;
  1601. end tasking;
  1602.  
  1603.                                                                Page 37
  1604.  
  1605.   APPENDIX A:  WOULD YOU LIKE A TEXTBOOK TO USE ALONG WITH ADA-TUTR?
  1606.  
  1607.      ADA-TUTR doesn't require a textbook, but a number of users have
  1608. asked us to recommend a book that would go well with this course.  We
  1609. made a special arrangement with John Wiley and Sons so that you can
  1610. buy the excellent textbook RENDEZVOUS WITH ADA 95 by David Naiditch
  1611. for only $44.95 plus sales tax.  Simply print the file COUPON.TXT, or
  1612. copy the coupon below.  Please send it to the address on the coupon,
  1613. not to Software Innovations Technology.
  1614.  
  1615. +--------------------------------------------------------------------+
  1616. |                                                                    |
  1617. | If you would like to have a textbook to go along with ADA-TUTR,    |
  1618. | send this coupon to                                                |
  1619. |                                                                    |
  1620. |                   Attn.: Jane Andolsek, 4th floor                  |
  1621. |                       Wiley - Training Sales                       |
  1622. |                        John Wiley and Sons                         |
  1623. |                          605 Third Avenue                          |
  1624. |                        New York, NY  10158                         |
  1625. |                                                                    |
  1626. | Please send me ______ copy(ies) of RENDEZVOUS WITH ADA 95, Second  |
  1627. | Edition, by David Naiditch, to examine for 15 days.                |
  1628. |                                                                    |
  1629. | Order #: 1-01276-9.  Price: $44.95 plus local sales tax, postage   |
  1630. | and handling.                                                      |
  1631. |                                                                    |
  1632. | [ ]  Bill me.                                                      |
  1633. |                                                                    |
  1634. | [ ]  Payment enclosed.  (Orders accompanied by payment will be     |
  1635. |      sent postpaid.)                                               |
  1636. |                                                                    |
  1637. | [ ]  Charge my   ___ VISA   ___ MasterCard   ___ American Express  |
  1638. |      (Note: Credit card orders are not considered prepayment.)     |
  1639. |                                                                    |
  1640. |      Account #: ________________________________                   |
  1641. |                                                                    |
  1642. |      Expiration Date: __________________________                   |
  1643. |                                                                    |
  1644. | NAME:____________________________ AFFILIATION:____________________ |
  1645. |                                                                    |
  1646. | ADDRESS:__________________________________________________________ |
  1647. |                                                                    |
  1648. | CITY/STATE/ZIP:_____________________ SIGNATURE:___________________ |
  1649. |                                  (Offer invalid without signature) |
  1650. |                                                                    |
  1651. | (Prices subject to change without notice and higher outside the    |
  1652. | U.S.A.)                                                            |
  1653. |                                                                    |
  1654. +--------------------------------------------------------------------+
  1655.  
  1656.                                                                Page 38
  1657.  
  1658.           APPENDIX B:  RUNNING BOOK TO PRINT ALL THE SCREENS
  1659.  
  1660.      If you're running ADA-TUTR on a PC, you can always print the
  1661. screen that's currently being displayed by holding a Shift key while
  1662. pressing the PrtSc key.
  1663.      However, several users wanted to be able to print ALL the screens
  1664. in the entire course, as one large book.  So, starting with version
  1665. 2.0 of ADA-TUTR, we added the program BOOK.  This program reads the
  1666. file ADA_TUTR.DAT and produces two large output files, which can then
  1667. be printed.  Be prepared to print about 500 pages!
  1668.      Simply type BOOK to run the program.
  1669.  
  1670.  
  1671.      BOOK creates plain ASCII files, double spaced the way this
  1672.                                      -------------
  1673. paragraph is double spaced.  It emphasizes text by placing hyphens
  1674.              -------------      ----------                 -------
  1675. below the lines like this.
  1676.                 ---------
  1677.  
  1678.  
  1679.      BOOK asks you for the name of the output file for the first half
  1680. of the tutorial.  After that file is written, BOOK asks for the name
  1681. of the output file for the second half of the tutorial.  You can then
  1682. print the output files.
  1683.      You can optionally specify the name PRN for both output files, to
  1684. have the output of BOOK go directly to the printer.
  1685.      Begin reading your printed output with screen 104.  Note that, at
  1686. the bottom of each page, there's a list of possible user responses
  1687. with screen numbers.  For example, at the bottom of Screen 104 you'll
  1688. see
  1689.  
  1690.   'Y' 107  'N' 122
  1691.  
  1692. This means that, if the user presses Y, screen 107 will be shown next,
  1693. and if the user presses N, screen 122 will be next.  Pressing X always
  1694. takes the user to screen 103.  The special "screen numbers" 098
  1695. through 100 appearing at the bottom of screens 107 and 108 are
  1696. explained in the introductory comments in ADA_TUTR.ADA.
  1697.      BOOK, like ADA-TUTR, will run on a PC or on any Ada-speaking
  1698. computer.
  1699.  
  1700.                                                                Page 39
  1701.  
  1702.          APPENDIX C:  SOME ADA COMPILERS AVAILABLE FOR THE PC
  1703.  
  1704.      Here's a brief list of DOS and Windows Ada compilers available
  1705. for the IBM PC and compatibles.  For this course, an Ada compiler is
  1706. helpful, but not required.  There are six Outside Assignments; most of
  1707. them ask you to write and compile a short Ada program.  If you don't
  1708. have access to an Ada compiler, just skip the Outside Assignments.
  1709.      Although we may now have a small financial interest in some of
  1710. the companies mentioned here (see page 5), we try to keep this list
  1711. unbiased.  If you know of an Ada compiler for the PC that should be on
  1712. this list, or if you have any updated information or corrections,
  1713. please contact us.
  1714.  
  1715. 1.  Augusta is a free compiler/interpreter found on some computer
  1716.     bulletin boards.  Augusta implements a very small subset of Ada 83
  1717.     with no packages, and some of the syntax is non-standard (e.g.,
  1718.     "elseif" instead of "elsif").  Augusta isn't really adequate for
  1719.     most of the Outside Assignments of ADA-TUTR.
  1720.  
  1721. 2.  Small Ada is another free compiler/interpreter implementing a
  1722.     small subset of Ada 83.  It is available at
  1723.     http://wuarchive.wustl.edu/languages/ada/compiler/smallada.  While
  1724.     Small Ada is a larger subset that Augusta, we recommend more
  1725.     complete compilers for those learning Ada.
  1726.  
  1727. 3.  New York University Ada/Ed is a free compiler/interpreter
  1728.     implementing Ada 83 completely.  GW-Ada/Ed is Ada/Ed with some
  1729.     enhancements (such as an editor) added by George Washington
  1730.     University, and is also free.  Both Ada/Ed and GW-Ada/Ed are
  1731.     available at
  1732.     http://wuarchive.wustl.edu/languages/ada/compiler/adaed.
  1733.  
  1734. 4.  AVLAda9X is a free Ada 95 programming environment available at
  1735.     http://wuarchive.wustl.edu/languages/ada/compiler/avlada9x.
  1736.  
  1737. 5.  GNAT is a popular free Ada 95 compiler that, in the DOS version,
  1738.     is complete except for tasking.  It is available at
  1739.     http://wuarchive.wustl.edu/languages/ada/compiler/gnat, and by
  1740.     anonymous FTP at cs.nyu.edu.  Versions are also available for
  1741.     Windows 95 and Windows NT at cs.nyu.edu and at
  1742.     ftp.cs.yale.edu/pub/gnat.  Additional tools for GNAT are sold by
  1743.     LabTek Corp., 565 Wagon Trail, Orange, CT 06477-2171, starting at
  1744.     $49.95.  Phone 203-877-2880, fax 203-877-4625, e-mail
  1745.     LabTek@cs.yale.edu.
  1746.  
  1747. 6.  Ez2load is a package containing GW-Ada/Ed, AVLAda9X, GNAT, and a
  1748.     number of other Ada tools, available at
  1749.     http://wuarchive.wustl.edu/languages/ada/compiler/ez2load, and by
  1750.     FTP at ftp.gwu.edu in the directory pub/ada/ez2load.
  1751.  
  1752.                            -- continued --
  1753.  
  1754.                                                                Page 40
  1755.  
  1756. 7.  Open Ada is sold by D.C. Heath Co., 2700 N. Richardt Ave.,
  1757.     Indianapolis, IN 46219-1186 for $66.67 plus tax and shipping.
  1758.     Phone 800-334-3284, 800-428-8071, 317-359-5585, or 617-862-6650,
  1759.     fax 800-824-7390.
  1760.  
  1761. 8.  ActivAda for Windows is sold by Thomson Software Products, 10251
  1762.     Vista Sorrento Parkway, Suite 300, San Diego, CA 92121-2718,
  1763.     starting at $99 ($75 for students) for the Personal Edition.  This
  1764.     edition does not have tasking and is intended for educational
  1765.     purposes.  A Professional Edition is also available.  Phone
  1766.     800-833-0042 or 617-221-7354.  E-mail activada@thomsoft.com, Web
  1767.     site http://www.thomsoft.com.
  1768.  
  1769. 9.  Janus/Ada is sold by R.R. Software, Inc., PO Box 1512, Madison, WI
  1770.     53701-1512, starting at $129.  Educational discounts are
  1771.     available.  Phone 800-722-3248 or 608-245-0375, e-mail
  1772.     info@rrsoftware.com.
  1773.  
  1774.                                                                Page 41
  1775.  
  1776.             APPENDIX D:  SAMPLE MULTI-USER SOFTWARE LICENSE
  1777.  
  1778.      Software Innovations Technology believes in a plain-English
  1779. software license that people can understand.  A sample license appears
  1780. on the next page.  However, if your company's lawyers would prefer a
  1781. differently worded license, simply contact us.  We'll be happy to
  1782. accommodate you.
  1783.      As you can see, the terms of our license are very generous.  We
  1784. allow you to make as many copies of ADA-TUTR as you like, and to
  1785. install it on as many computers as you like, regardless of the
  1786. computer type (laptop, desktop, workstation, mainframe, etc.)  Also,
  1787. you may use ADA-TUTR at all your geographical locations, which is why
  1788. we use the term Multi-User License rather than Site License.  The only
  1789. thing we limit is the total number of people who may use ADA-TUTR
  1790. (except in the case of an unlimited license).  Please remember that if
  1791. 100 people use ADA-TUTR now and 100 others use it later, that counts
  1792. as 200 users, not 100.
  1793.      In the sample license on the next page, comments appear in
  1794. brackets.  These comments are not part of the actual license.
  1795.  
  1796.                                                                Page 42
  1797.  
  1798.                  [SAMPLE] MULTI-USER SOFTWARE LICENSE
  1799.  
  1800.                     Software Innovations Technology
  1801.                         1083 Mandarin Drive NE
  1802.                        Palm Bay, FL  32905-4706
  1803.                             (407) 951-0233
  1804.  
  1805.    This license conveys to XYZ Company the right to use the comput-
  1806.    er program  ADA-TUTR, the Interactive Ada Tutor,  under the fol-
  1807.    lowing conditions:
  1808.  
  1809.    1.  The program shall remain  the property of  Software  Innova-
  1810.    tions Technology.
  1811.  
  1812.    2.  The program may be freely copied and installed on any or all
  1813.    computers of  XYZ Company,  regardless of geographical location.
  1814.    Copies of the program may be distributed outside XYZ Company for
  1815.    others to evaluate on a trial basis.
  1816.  
  1817.    3.  This license is perpetual.
  1818.  
  1819.    4.  The number of  XYZ Company  personnel [or "students and per-
  1820.    sonnel of XYZ University"] who may use the program is unlimited.
  1821.                              [*** OR ***]
  1822.    4.  The total number of XYZ Company personnel  [or "students and
  1823.    personnel of  XYZ  University"]  who use the program,  excluding
  1824.    those who only briefly evaluate it, shall not exceed  two  thou-
  1825.    sand (2000)  [or "five hundred (500)"  or  "one hundred (100)"].
  1826.    In calculating the number of users,  XYZ Company must always add
  1827.    the number of people  currently  using the program to the number
  1828.    who have used it in the past.
  1829.  
  1830.    5.  [This paragraph is omitted in unlimited licenses.]  Software
  1831.    Innovations Technology  sells  licenses  for  larger  numbers of
  1832.    users.  XYZ Company may, at any time, upgrade this license for a
  1833.    larger number of users by paying,  to Software Innovations Tech-
  1834.    nology, the difference in price between the two licenses.
  1835.  
  1836.    6.  This license is not transferable.
  1837.  
  1838.    7.  The Disclaimer of Warranty, included in the program documen-
  1839.    tation, applies as if included in this license.
  1840.  
  1841.    8.  [This paragraph is  omitted  if the order is prepaid.]  This
  1842.    license shall be  void  if the invoice is not paid within thirty
  1843.    (30) days of the date of this license.
  1844.  
  1845.  
  1846.    (Signed)________________________________  Date _________________
  1847.  
  1848.            John J. Herro, President
  1849.            Software Innovations Technology
  1850.  
  1851.                                                                Page 43
  1852.  
  1853.          APPENDIX E:  INSTALLING ADA-TUTR ON OTHER COMPUTERS
  1854.  
  1855.      Because source code is included with ADA-TUTR, you can install
  1856. ADA-TUTR on almost any computer that has an Ada 83 or Ada 95 compiler,
  1857. from compact units to large mainframes.  ADA-TUTR is written in Ada
  1858. (of course!), and Ada programs tend to be very portable.
  1859.      The screen should have at least 24 rows of 80 characters each,
  1860. and should support the ANSI escape sequences for highlighting, reverse
  1861. video, cursor positioning, etc.  Almost all computers qualify.
  1862.      You need a way to send text files from your PC to the other
  1863. computer.  Files are usually sent to large mainframes with the program
  1864. KERMIT, which is in the public domain.  One version of KERMIT runs on
  1865. the PC, another on the mainframe.  The two communicate with each
  1866. other.  Sometimes XMODEM or another protocol is used instead of
  1867. KERMIT.
  1868.      If a communications program is available on the PC but not on the
  1869. other computer, you can still send text files, but not as efficiently.
  1870. Connect your PC as a terminal and tell the other computer to copy the
  1871. keyboard to a new file.  For example, on a VAX computer running VMS,
  1872. the command is "COPY TT: filename.ext" (without the quotes).  Then
  1873. tell your communications program to send (or "upload") the file, using
  1874. ASCII protocol, and stripping line feeds.  After the file is sent,
  1875. type the appropriate end-of-file character for the other computer.  On
  1876. a VAX running VMS, you would type Control-Z.  Since this method of
  1877. file transfer doesn't do error checking, you may have to send each
  1878. file twice using two different names, and compare the two files with
  1879. each other on the other computer.  It's far better to use a
  1880. communications program on the other computer, if one is available.
  1881.      OK, you have some means of sending text files.  You won't have to
  1882. send other kinds of files.  To install ADA-TUTR on the other computer,
  1883. just follow these steps:
  1884.  
  1885. 1.  Type DAT2TXT on the PC.  This will read the file ADA_TUTR.DAT,
  1886. which is not a text file, and create a new text file TUTOR.TXT, which
  1887. can be sent to the other computer.  DAT2TXT will probably take several
  1888. minutes to run.  Don't try to bypass this step even if you're able to
  1889. send non-text files.  It's important that you send TUTOR.TXT and not
  1890. ADA_TUTR.DAT, because the PC version of ADA_TUTR.DAT doesn't work on
  1891. some systems.
  1892.  
  1893. 2.  Decide where ADA-TUTR will reside on the other computer, so that
  1894. it will be available to all users.  For example, on a VAX computer
  1895. running VMS, the tutor is usually placed in SYS$INSTRUCTION.  It could
  1896. also be placed in SYS$MANAGER, etc.
  1897.  
  1898.                            -- continued --
  1899.  
  1900.                                                                Page 44
  1901.  
  1902. 3.  Send to the other computer all the files that come with ADA-TUTR,
  1903. except ADA_TUTR.DAT and the files ending in .COM.  Be sure to send
  1904. TUTOR.TXT, created in step 1.  Don't try to send ADA_TUTR.DAT and the
  1905. .COM files, because they're not text files.  Also note that ADA-TUTR
  1906. creates a file ADA_TUTR.USR the first time it's run.  Do NOT send that
  1907. file, because it also is not a text file.  If our file names are
  1908. illegal on the other system, you'll have to rename them as they're
  1909. sent.  (We haven't seen a system where our file names are illegal.)
  1910.  
  1911. 4.  If any of the file names ADA_TUTR.DAT, ADA_TUTR.USR, or TUTOR.TXT
  1912. are illegal on your system, edit the files ADA_TUTR.ADA, BOOK.ADA,
  1913. CHANGESN.ADA, and TXT2DAT.ADA to show new, legal file names.  Search
  1914. for the old file names and replace them with the new ones.
  1915.  
  1916. 5.  Note that each user will probably run ADA-TUTR from his or her own
  1917. file directory.  There will be a file ADA_TUTR.USR in each user's
  1918. directory, but all the other files will reside in a common area, such
  1919. as SYS$INSTRUCTION, etc.  Therefore, edit the files ADA_TUTR.ADA,
  1920. BOOK.ADA, CHANGESN.ADA, and TXT2DAT.ADA to show the full path name of
  1921. the file ADA_TUTR.DAT.  On a VAX system, for example, you might search
  1922. for the name ADA_TUTR.DAT and replace it with
  1923. SYS$INSTRUCTION:ADA_TUTR.DAT.
  1924.  
  1925. 6.  On one system we encountered, Ada source file names must end in .a
  1926. rather than .ADA.  If that's the case on your system, rename all the
  1927. .ADA files.
  1928.  
  1929. 7.  On the other computer, compile, link, and run TXT2DAT.ADA.  Some
  1930. systems call the linking step "binding."  This program will read
  1931. TUTOR.TXT and create ADA_TUTR.DAT on the other system.  If you wish,
  1932. you may then delete TUTOR.TXT.
  1933.  
  1934. 8.  If you're using VAX Ada, skip to page 46.  If you're using a UNIX
  1935. based system that has a C compiler with the ability to link into Ada
  1936. programs, skip to page 47.  Otherwise, continue with the next page.
  1937. If you're not certain, continue with the next page.
  1938.  
  1939.                            -- continued --
  1940.  
  1941.                                                                Page 45
  1942.  
  1943.  
  1944. 9.  Compile VANILLA.ADA, but don't try to link or run it.  This "plain
  1945. vanilla" file will work with any standard Ada compiler.
  1946.  
  1947. 10.  Compile ADA_TUTR.ADA.
  1948.  
  1949. 11.  Link, giving the name of the main program, ADA_TUTR.  This will
  1950. produce an executable file, which on most systems will be called
  1951. ADA_TUTR.EXE.  However, on a few systems the executable file will have
  1952. a strange name, so rename the executable file if necessary.
  1953.  
  1954. 12.  Run ADA-TUTR.  The command is usually ADA_TUTR or RUN ADA_TUTR.
  1955. Note that, on some systems, you'll have to strike ENTER (or RETURN or
  1956. NEW-LINE) after each response, even though the program says, "You need
  1957. not hit ENTER."  The reason is that some systems require you to strike
  1958. ENTER when they read the keyboard through TEXT_IO.  Also note that some
  1959. of the tutorial text refers to commands that are meant for a PC, such
  1960. as COPY and PRINT.  These commands may have to be varied slightly to
  1961. work on your system.
  1962.  
  1963. 13.  Define a command so that each user will be able to run ADA-TUTR
  1964. easily.
  1965.  
  1966.  
  1967. We'll be happy to help you install ADA-TUTR and get it running, even
  1968. if you haven't registered or bought a license.  We want you to try
  1969. ADA-TUTR before paying for it.
  1970.  
  1971.                                                                Page 46
  1972.  
  1973.                    SPECIAL INSTRUCTIONS FOR VAX ADA
  1974.  
  1975. 9.  If you're using VAX Ada, compile VAX.ADA, but don't try to link or
  1976. run it.  The file VANILLA.ADA would work, but VAX.ADA makes it
  1977. unnecessary to strike RETURN after each response.  The reason is that
  1978. VAX.ADA gets characters from the keyboard by calling the System
  1979. Service routines, without going through TEXT_IO.
  1980.  
  1981. 10.  Compile ADA_TUTR.ADA.
  1982.  
  1983. 11.  Link, giving the name of the main program, ADA_TUTR.  The command
  1984. is ACS LINK ADA_TUTR.  This will produce an executable file,
  1985. ADA_TUTR.EXE.
  1986.  
  1987. 12.  Run ADA-TUTR by typing RUN ADA_TUTR.  Note that some of the
  1988. tutorial text refers to commands that are meant for a PC, such as COPY
  1989. and PRINT.  These commands may have to be varied slightly to work on
  1990. your system.  For example, when the text says to type
  1991. COPY TRITYPE.DUM TRITYPE.ADA, your users might have to type
  1992. COPY SYS$INSTRUCTION:TRITYPE.DUM TRITYPE.ADA.
  1993.  
  1994. 13.  Define a command so that each user will be able to run ADA-TUTR
  1995. easily.  For example, you might add the following line to SYLOGIN.COM:
  1996.  
  1997.             $ TEACHADA :== "RUN SYS$INSTRUCTION:ADA_TUTR"
  1998.  
  1999.  
  2000. We'll be happy to help you install ADA-TUTR and get it running, even
  2001. if you haven't registered or bought a license.  We want you to try
  2002. ADA-TUTR before paying for it.
  2003.  
  2004.                                                                Page 47
  2005.  
  2006.              SPECIAL INSTRUCTIONS FOR UNIX BASED SYSTEMS
  2007.  
  2008. 9.  If you're using a UNIX based system with a C compiler, and your
  2009. Ada compiler can link with modules produced by C, compile ONECHAR.C
  2010. with the C compiler.  If you can't compile ONECHAR.C because your
  2011. system doesn't have the include file TERMIO.H, then compile ALTCHAR.C
  2012. instead.  However, if you compile ALTCHAR.C, you'll have to invoke
  2013. ADA-TUTR between two calls to stty, in a script file.  For example:
  2014.                      stty raw
  2015.                      /usr/local/ada-tutr/ada_tutr
  2016.                      stty -raw
  2017.  
  2018. 10.  Compile UNIX.ADA, but don't try to link or run it.  The file
  2019. VANILLA.ADA would work, but UNIX.ADA, when used with ONECHAR.C or
  2020. ALTCHAR.C, makes it unnecessary to strike RETURN after each response.
  2021. The reason is that ONECHAR.C and ALTCHAR.C get characters directly
  2022. from the keyboard, without going through TEXT_IO.
  2023.  
  2024. 11.  Compile ADA_TUTR.ADA.
  2025.  
  2026. 12.  Link, giving the name of the main program, ADA_TUTR.  Include the
  2027. object file from the C compiler in the link.  This will create an
  2028. executable file, called ADA_TUTR on most systems.  (On one system we
  2029. encountered, the file created was named a.out.)  If necessary, rename
  2030. the executable file to an appropriate name, such as ada_tutr or
  2031. ADA_TUTR or ADA_TUTR.EXE.
  2032.  
  2033.  
  2034. Here are sample steps 9 through 12 for two UNIX based systems:
  2035.  
  2036.        ON A UNISYS 5000/80:             ON A HARRIS HCX:
  2037.  
  2038.        cc -c onechar.c                  cc -c onechar.c
  2039.        ada unix.ada ada_tutr.ada        ada unix.a ada_tutr.a
  2040.        ald -p'onechar' ada_tutr         a.ld ada_tutr onechar.o
  2041.                                         mv a.out ada_tutr
  2042.  
  2043.  
  2044. 13.  Run ADA-TUTR.  Usually this is done by typing ada_tutr.  Note
  2045. that some of the tutorial text refers to commands that are meant for a
  2046. PC, such as COPY and PRINT.  These commands may have to be varied
  2047. slightly to work on your system.
  2048.  
  2049. 14.  Define a command so that each user will be able to run ADA-TUTR
  2050. easily.
  2051.  
  2052.  
  2053. We'll be happy to help you install ADA-TUTR and get it running, even
  2054. if you haven't registered or bought a license.  We want you to try
  2055. ADA-TUTR before paying for it.
  2056.  
  2057.                                                                Page 48
  2058.  
  2059.           APPENDIX F:  WE LISTEN!  NEW FEATURES OF ADA-TUTR
  2060.  
  2061.      Almost all of the features added to ADA-TUTR were done as a
  2062. result of your comments and suggestions.  Thank you very much, and
  2063. please continue to send them!  We want to produce the very best Ada
  2064. Tutor possible.  Here's a history of revisions to ADA-TUTR.  In
  2065. addition to the changes shown here, we're constantly making minor
  2066. improvements in the tutorial text and updating the list of Ada
  2067. compilers available for the PC (page 39).
  2068.  
  2069. VERSION 3.11:
  2070.      Added our e-mail addresses and recompiled with Janus/Ada.
  2071.  
  2072. VERSION 3.10:
  2073.      Changed all Ada 9X references Ada 95.
  2074.      Added comparisons of Ada with C and C++.
  2075.      Changed the documentation to assume that all customers now want
  2076. 3.5-inch diskettes, unless they check the 5.25-inch diskette box in
  2077. INVOICE.TXT.
  2078.  
  2079. VERSION 3.00:
  2080.      Added much new material to cover Ada 9X, and changed the
  2081. capitalization style of all Ada code from that of the Ada 83 RM to
  2082. that of the Ada 9X RM.
  2083.      Removed references to PC-Write, because recent versions of DOS
  2084. include a screen editor.
  2085.      Replaced JANUS.ADA with JANUS16.PKG and JANUS32.PKG.
  2086.  
  2087. VERSION 2.02:
  2088.      Added the files DESC.SDI and FILE_ID.DIZ, briefly describing
  2089. ADA-TUTR.
  2090.      Improved ED.ADA to take advantage of the newest version PC-Write,
  2091. called PC-Write Advanced Level.
  2092.  
  2093. VERSION 2.01:
  2094.      Added the file JANUS.ADA.
  2095.  
  2096. VERSION 2.00:
  2097.      Changed the ADA_TUTR.DAT file to a more compact format, so that
  2098. ADA-TUTR would take less room on a hard disk and be able to run from a
  2099. floppy diskette.
  2100.      Added the BOOK program to print all of the tutorial screens as a
  2101. large book (page 38).
  2102.      Updated Outside Assignment 6 to make it easier to see where the
  2103. 5-second intervals occur.
  2104.      Added the sample Multi-User License (pages 41-42).
  2105.      Added the special offer for a textbook (page 37).
  2106.  
  2107. VERSION 1.22:
  2108.      Added ALTCHAR.C for UNIX based systems that don't have the file
  2109. TERMIO.H.  (Thank you, Mr. Richard Conn, 22 Hunt Court, Tinton Falls,
  2110. NJ 07753.)
  2111.  
  2112.                                                                Page 49
  2113.  
  2114. VERSION 1.21:
  2115.      Added ONECHAR.C so users of UNIX based systems wouldn't have to
  2116. strike ENTER after each response.  (Thank you, Mr. David Hill, 7549
  2117. Wynford Street, Salt Lake City, UT 84121.)
  2118.      Changed all hyphens in file names to underlines, at the request
  2119. of PC-SIG, so that ADA-TUTR would be compatible with High Sierra
  2120. Format CD-ROMs.
  2121.  
  2122. VERSION 1.20:
  2123.      Added the ability to select background, foreground, and border
  2124. colors on a PC without sacrificing compatibility with mainframe
  2125. computers and monochrome PCs.
  2126.      Made ADA-TUTR automatically remember where you leave off when you
  2127. exit the program, so that you don't have to write down the screen
  2128. number.  Also made ADA-TUTR remember your color choices.
  2129.      Made ADA-TUTR tell you the current screen number and the
  2130. approximate percentage through the course when you strike X, and added
  2131. the ability to go back to the last question or to the last Outside
  2132. Assignment.
  2133.      Added a special screen at the start of each major section,
  2134. showing an outline of the course.
  2135.      Updated the tutorial text to reflect the government's new policy
  2136. regarding expiration of Validation Certificates.
  2137.      Updated the tutorial text to show that the newest Ada compilers
  2138. now raise CONSTRAINT_ERROR where NUMERIC_ERROR was once raised.
  2139.      Added the offer for customized versions of ADA-TUTR, and for the
  2140. Customization Kit (page 4).
  2141.      Recompiled ADA-TUTR using a validated compiler from Meridian
  2142. Software Systems, Inc., instead of an older unvalidated compiler from
  2143. Artek, Inc.
  2144.      Made ADA-TUTR available on 3.5" as well as 5.25" diskettes.
  2145.  
  2146. VERSION 1.01:
  2147.      Fixed minor typographical errors in Version 1.00.
  2148.  
  2149.                                                                Page 50
  2150.  
  2151.                  APPENDIX G:  DISCLAIMER OF WARRANTY
  2152.  
  2153. We hate legal mumbo jumbo, but we have to say the following to protect
  2154. ourselves:
  2155.  
  2156. Software Innovations Technology makes no warranty of any kind,
  2157. expressed or implied, including any warranties of merchantability or
  2158. fitness for a particular purpose.  We shall not be liable for any
  2159. damages, whether direct, indirect, incidental, special, or
  2160. consequential, arising from a failure of this program to operate in a
  2161. manner desired by the user.  We shall not be liable for any damage to
  2162. data or property which may be caused directly or indirectly by use of
  2163. this program.  IN NO EVENT SHALL SOFTWARE INNOVATIONS TECHNOLOGY BE
  2164. LIABLE FOR ANY DAMAGES, INCLUDING ANY LOST PROFITS, LOST SAVINGS, OR
  2165. OTHER INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR
  2166. INABILITY TO USE THIS PROGRAM, OR FOR ANY CLAIM BY ANY OTHER PARTY.
  2167.